<?php

namespace App\Admin\Controllers;


use App\Topic;

class TopicController extends Controller
{
    //专题列表页面
    public function index()
    {
        $topics = Topic::all();
        
        return view('admin/topic/index', compact('topics'));
    }

    //专题创建页面
    public function create()
    {
        return view('admin/topic/create');
    }

    //保存专题
    public function store()
    {
        $this->validate(request(), [
            'name'  => 'required|min:3',
        ]);

        Topic::create(['name' => request('name')]);

        return redirect('/admin/topics');
    }

    //删除专题
    public function destroy(Topic $topic)
    {
        $topic->delete();

        return [
            'error' => 0,
            'msg'   => ''
        ];
    }
}
